<template>
  <div>
    <el-dialog
      title="新增第三方企业/会员"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      width="50%"
      :before-close="handleClose"
      @close="close"
    >
      <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
        <el-form-item label="企业名称:" prop="userGroupName">
          <el-input v-model="ruleForm.userGroupName" />
        </el-form-item>
        <el-form-item label="顶部名称:" prop="nameTop">
          <el-input v-model="ruleForm.nameTop" />
        </el-form-item>
        <el-form-item label="版权:" prop="nameBottom">
          <el-input v-model="ruleForm.nameBottom" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer" />
    </el-dialog>
  </div>
</template>

<script>
import Vip from '@/api/axios/api/author/vip'
import Tip from '@/utils/tip'
export default {
  name: 'VipAdd',
  props: {
    hideAddCompBoolean: Boolean
  },
  data() {
    return {
      dialogVisible: false,
      ruleForm: {
        userGroupName: '',
        nameTop: '',
        nameBottom: ''
      },
      rules: {
        userGroupName: [
          { required: true, message: '请输入企业名称', trigger: 'blur' }
        ],
        nameTop: [
          { required: true, message: '请输入顶部名称', trigger: 'blur' }
        ],
        nameBottom: [
          { required: true, message: '请输入版权名称', trigger: 'blur' }
        ]
      }
    }
  },
  watch: {
    hideAddCompBoolean: {
      handler() {
        this.dialogVisible = this.hideAddCompBoolean
      }
    }
  },
  methods: {
    close() {
      this.$emit('hideAddChildComp', false)
    },
    handleClose(done) {
      this.$emit('hideAddChildComp', false)
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          Vip.vipAdd(this.ruleForm).then(res => {
            if (res.status === 200) {
              Tip.success(res.data)
              this.$emit('hideAddChildComp', false)
            } else {
              Tip.error(res.data)
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style scoped>

</style>
